home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ButtonLink / ButtonLink.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  5.7 KB  |  223 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Button;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.LayoutManager;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.net.MalformedURLException;
  11. import java.net.URL;
  12. import java.net.URLEncoder;
  13. import java.util.EventObject;
  14.  
  15. public class ButtonLink extends Applet implements ActionListener {
  16.    private String url;
  17.    private String text;
  18.    private String target;
  19.    // $FF: renamed from: wi int
  20.    private int field_0;
  21.    // $FF: renamed from: he int
  22.    private int field_1;
  23.    private int wib;
  24.    private int heb;
  25.    // $FF: renamed from: b java.awt.Button
  26.    private Button field_2;
  27.    private Color backCol;
  28.    private Color buttonCol;
  29.    private AudioClip sound;
  30.    private AudioClip clicSound;
  31.    private boolean loopSound;
  32.  
  33.    public String getAppletInfo() {
  34.       return "Name: ButtonLink\r\nAuthor: Taiji Software";
  35.    }
  36.  
  37.    public void register() {
  38.       try {
  39.          URL u = new URL("http://www.taijisoftware.com");
  40.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  41.       } catch (Exception e) {
  42.          System.out.println(e);
  43.          this.stop();
  44.       }
  45.    }
  46.  
  47.    public void init() {
  48.       String codeBase = null;
  49.  
  50.       try {
  51.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  52.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  53.          codeBase = codeBase.toUpperCase();
  54.       } catch (Exception var9) {
  55.       }
  56.  
  57.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  58.          String regCode = ((Applet)this).getParameter("registration_code");
  59.          if (regCode == null) {
  60.             regCode = ((Applet)this).getParameter("reg_domain");
  61.             if (regCode == null) {
  62.                this.register();
  63.             } else {
  64.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  65.                   codeBase = "WWW." + codeBase;
  66.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  67.                   codeBase = codeBase.substring(4);
  68.                }
  69.  
  70.                char[] chars = new char[codeBase.length()];
  71.                codeBase.getChars(0, codeBase.length(), chars, 0);
  72.                String key = new String("haricot");
  73.                char[] chars2 = new char[key.length()];
  74.                key.getChars(0, key.length(), chars2, 0);
  75.  
  76.                for(int i = 0; i < codeBase.length(); ++i) {
  77.                   int j;
  78.                   if (i >= key.length()) {
  79.                      j = i - key.length() * (i / key.length());
  80.                   } else {
  81.                      j = i;
  82.                   }
  83.  
  84.                   chars[i] += chars2[j];
  85.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  86.                }
  87.  
  88.                String res = new String(chars);
  89.                if (!res.equalsIgnoreCase(regCode)) {
  90.                   this.register();
  91.                }
  92.             }
  93.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  94.             this.register();
  95.          }
  96.       }
  97.  
  98.       this.getParameters();
  99.       ((Container)this).setLayout((LayoutManager)null);
  100.       this.field_2 = new Button(this.text);
  101.       this.field_2.setSize(this.wib, this.heb);
  102.       this.field_2.addActionListener(this);
  103.       ((Container)this).add(this.field_2);
  104.       this.field_2.setLocation((this.field_0 - this.wib) / 2, (this.field_1 - this.heb) / 2);
  105.       ((Component)this).setBackground(this.getColor("background_color"));
  106.       this.field_2.setBackground(this.getColor("button_color"));
  107.       if (this.sound != null) {
  108.          if (this.loopSound) {
  109.             this.sound.loop();
  110.             return;
  111.          }
  112.  
  113.          this.sound.play();
  114.       }
  115.  
  116.    }
  117.  
  118.    public void stop() {
  119.       if (this.sound != null) {
  120.          this.sound.stop();
  121.       }
  122.  
  123.    }
  124.  
  125.    public void getParameters() {
  126.       this.field_0 = ((Component)this).getSize().width;
  127.       this.field_1 = ((Component)this).getSize().height;
  128.       this.text = ((Applet)this).getParameter("text");
  129.       String s = ((Applet)this).getParameter("button_width");
  130.       if (s != null) {
  131.          this.wib = Integer.parseInt(s);
  132.       } else {
  133.          this.wib = this.field_0;
  134.       }
  135.  
  136.       s = ((Applet)this).getParameter("button_height");
  137.       if (s != null) {
  138.          this.heb = Integer.parseInt(s);
  139.       } else {
  140.          this.heb = this.field_1;
  141.       }
  142.  
  143.       this.url = ((Applet)this).getParameter("link");
  144.       this.target = ((Applet)this).getParameter("target");
  145.       if (this.target == null) {
  146.          this.target = "_self";
  147.       }
  148.  
  149.       s = ((Applet)this).getParameter("sound_name");
  150.       if (s != null) {
  151.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  152.       }
  153.  
  154.       s = ((Applet)this).getParameter("loop_sound");
  155.       if (s != null) {
  156.          if (s.equals("yes")) {
  157.             this.loopSound = true;
  158.          } else {
  159.             this.loopSound = false;
  160.          }
  161.       }
  162.  
  163.       s = ((Applet)this).getParameter("clic_sound_name");
  164.       if (s != null) {
  165.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  166.       }
  167.  
  168.    }
  169.  
  170.    private Color getColor(String param) {
  171.       String s = ((Applet)this).getParameter(param);
  172.       if (s != null) {
  173.          if (s.substring(0, 1).equals("#")) {
  174.             s = s.substring(1);
  175.             int i = Integer.parseInt(s, 16);
  176.             return new Color(i);
  177.          } else {
  178.             return null;
  179.          }
  180.       } else {
  181.          return null;
  182.       }
  183.    }
  184.  
  185.    public URL giveURL(String url) {
  186.       try {
  187.          if (url.toUpperCase().startsWith("HTTP")) {
  188.             return new URL(url);
  189.          } else if (url.toUpperCase().startsWith("FTP")) {
  190.             int p = url.indexOf(":");
  191.             int p2 = url.indexOf(":", p + 1);
  192.             if (p2 != -1) {
  193.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  194.             }
  195.  
  196.             p = url.indexOf("%40");
  197.             if (p != -1) {
  198.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  199.             }
  200.  
  201.             return new URL(url);
  202.          } else {
  203.             return new URL(((Applet)this).getCodeBase(), url);
  204.          }
  205.       } catch (MalformedURLException e) {
  206.          System.out.println(e);
  207.          return null;
  208.       }
  209.    }
  210.  
  211.    public void actionPerformed(ActionEvent event) {
  212.       if (((EventObject)event).getSource() instanceof Button) {
  213.          if (this.clicSound != null) {
  214.             this.clicSound.play();
  215.          }
  216.  
  217.          URL u = this.giveURL(this.url);
  218.          ((Applet)this).getAppletContext().showDocument(u, this.target);
  219.       }
  220.  
  221.    }
  222. }
  223.